function content0LoadFunction() {
	x_getContactsByProgram(contactsViewObj.returnGetContacts);
}

function content1LoadFunction() {
	var pID = $('mainProgramID').value;
	x_getContactsForProgram(pID,contactsViewObj.returnGetContactsForProgram);
}

var contactsViewObj = {
	returnGetContacts : function(string) {
		$('contactsContainer').innerHTML = string;
	},
	getContactsByProgram : function() {
		x_getContactsByProgram(contactsViewObj.returnGetContacts);
		$('buttonSortProgram').style.display = 'none';
		$('buttonSortLastName').style.display = '';		
		$('itemID').value = 0;	
	},
	getContactsByLastName : function() {
		x_getContactsByLastName(contactsViewObj.returnGetContacts);
		$('buttonSortProgram').style.display = '';
		$('buttonSortLastName').style.display = 'none';		
		$('itemID').value = 1;	
	},
	getContactsForProgram : function() {
		
	},
	returnGetContactsForProgram : function(string) {
		$('programContactDisplay').innerHTML = string;
	}
	
}

var contactsAddObj = {
	addContact : function() {		
		// Set hidden field defaults
		$('formAction').value = 'add';
		$('uID').value = '0';
		
		contactsSupportObj.openContactForm();		
	},
	returnAddContact : function() {
		
	}
}

var contactsDeleteObj = {
	returnDeleteContact : function(uID) {
		Effect.Fade('contactContainer'+uID, {delay: .5, duration: 1});
	}
}

var programEditObj = {
	editProgram : function(pID) {
		x_getProgramDetails(pID,1,programEditObj.returnGetProgramForEdit);
	},
	returnGetProgramForEdit : function(string) {
		stringArray = string.split('|');
		
		var pID   = stringArray[0];
		var pName = stringArray[1];
		var pCounty = stringArray[2];
		var pAddress = stringArray[3];
		var pCity    = stringArray[4];
		var pZip     = stringArray[5];
		var pURL     = stringArray[6];
		var pPhone1  = stringArray[7];
		var pPhone2  = stringArray[8];
		var pEmail   = stringArray[9];
		
		// Create form and drop into DOM
		var formHTML = '<div class="blueBox">';
		formHTML    += '<table style="width: 100%;"><tr><td style="width: 50%; vertical-align: top;">';
		formHTML    += '<b>Program Name</b><br />';
		formHTML    += '<input type="text" style="width: 300px;" id="pName'+pID+'" value="'+pName+'" /><br />';
		formHTML    += '<b>Address</b><br />';
		formHTML    += '<input type="text" style="width: 300px;" id="pAddress'+pID+'" value="'+pAddress+'" /><br />';
		formHTML    += '<b>City, Zip</b><br />';
		formHTML    += '<input type="text" style="width: 200px; margin-right: 10px;"id="pCity'+pID+'" value="'+pCity+'" />&nbsp;';
		formHTML    += '<input type="text" style="width: 85px;" id="pZip'+pID+'" value="'+pZip+'" /><br />';
		formHTML    += '<b>County</b><br />';
		formHTML    += '<input type="text" style="width: 300px;" id="pCounty'+pID+'" value="'+pCounty+'" /><br />';
		
		formHTML    += '</td><td style="vertical-align: top;">';
		
		formHTML    += '<b>Phone Numbers</b><br />';
		formHTML    += '<input type="text" style="width: 145px; margin-right: 10px;" id="pPhone1'+pID+'" value="'+pPhone1+'" />&nbsp;';
		formHTML    += '<input type="text" style="width: 140px;" id="pPhone2'+pID+'" value="'+pPhone2+'" /><br />';
		
		formHTML    += '<b>Email Address</b><br />';
		formHTML    += '<input type="text" style="width: 300px;" id="pEmail'+pID+'" value="'+pEmail+'" /><br />';
		
		formHTML    += '<b>Website</b><br />';
		formHTML    += '<input type="text" style="width: 300px;" id="pURL'+pID+'" value="'+pURL+'" /><br />';
		
		formHTML    += '</td></tr></table>';
		
		formHTML    += '<div style="margin-top: 5px;"><img src="../images/buttonSave.gif" style="cursor: pointer; border: none;" onClick="programEditObj.saveProgram('+pID+'); return false;" alt="Save" />&nbsp;';
		formHTML    += '<img src="../images/buttonCancel.gif" style="cursor: pointer; border: none;" onClick="programEditObj.cancelProgram('+pID+'); return false;" alt="Cancel" /></div>';
				
		formHTML    += '</div>'; 
		
		$('programForm'+pID).innerHTML = formHTML;
		new Effect.SlideDown('programForm'+pID, {direction: 'top', duration: .3});		
		$('programInfo'+pID).style.display = 'none';
	},
	saveProgram : function(pID) {
		var pName    = $('pName'+pID).value;
		var pCounty  = $('pCounty'+pID).value;
		var pAddress = $('pAddress'+pID).value;
		var pCity    = $('pCity'+pID).value;
		var pZip     = $('pZip'+pID).value;
		var pURL     = $('pURL'+pID).value;
		var pPhone1  = $('pPhone1'+pID).value;
		var pPhone2  = $('pPhone2'+pID).value;
		var pEmail   = $('pEmail'+pID).value;
		
		var phpArray = pID+'|'+pName+'|'+pCounty+'|'+pAddress+'|'+pCity+'|';
		phpArray    += pZip+'|'+pURL+'|'+pPhone1+'|'+pPhone2+'|'+pEmail;
		
		x_saveProgram(phpArray,programEditObj.returnSaveProgram); 
		contactsSupportObj.closeProgramForm(pID);
	},
	returnSaveProgram : function(string) {
		stringArray = string.split('|');		
		var pID   = stringArray[0];
		var pName = stringArray[1];
		$('programName'+pID).innerHTML = pName;
	},
	cancelProgram : function(pID) {
		contactsSupportObj.closeProgramForm(pID);
	}
}	

var contactsEditObj = {
	editContact : function(uID) {
		x_getContactForEdit(uID,contactsEditObj.returnGetContactForEdit);
	},
	returnGetContactForEdit : function(string) {
		stringArray = string.split('|');
		var uID       = stringArray[0];
		var programID = stringArray[1];
		var nameFirst = stringArray[2];
		var nameLast  = stringArray[3];
		var email     = stringArray[4];
		var phone1    = stringArray[5];
		var phone2    = stringArray[6];
		var officeNo  = stringArray[7];
		var positionID= stringArray[8];
		var uPublic   = stringArray[9];
		
		if (phone1 == 0) {
			phone1 = '';
		}
		if (phone2 == 0) {
			phone2 = '';
		}
		if (officeNo == 0) {
			officeNo = '';
		}		
	
		// Populate form
		$('uNameFirst').value = nameFirst;
		$('uNameLast').value  = nameLast;
		$('uPhone1').value    = phone1;
		$('uPhone2').value    = phone2;
		$('uEmail').value     = email;
		$('uOfficeNo').value  = officeNo;
		if (uPublic == 1) {
			$('uPublic').checked = true;
		} else {
			$('uPublic').checked = false;
		}	
		
		var uProgramOptions = $('uProgram').options;
		for(a=0;a<uProgramOptions.length;a++) {
			if ($('uProgram').options[a].value == programID) {
				$('uProgram').options[a].selected = true;
			}
		}
		
		var uPositionsOptions = $('uPosition').options;
		for(a=0;a<uPositionsOptions.length;a++) {
			if ($('uPosition').options[a].value == positionID) {
				$('uPosition').options[a].selected = true;
			}
		}
		
		// Set formAction and uID
		$('formAction').value = 'edit';
		$('uID').value        = uID;
				
		// Open form
		contactsSupportObj.openContactForm();
	}
}

var contactsSaveObj = {
	saveContact : function() {
		var action    = $('formAction').value;
		var uID       = $('uID').value;
		var nameFirst = $('uNameFirst').value;
		var nameLast  = $('uNameLast').value;
		var phone1    = $('uPhone1').value;
		var phone2    = $('uPhone2').value;
		var email     = $('uEmail').value;
		var officeNo  = $('uOfficeNo').value;
		var uPosition = $('uPosition').options;
		var uPosition = uPosition[uPosition.selectedIndex].value;
		if ($('uPublic').checked == true) {
			var uPublic = 1;
		} else {
			var uPublic = 0;
		}
		
		var phpString  = uID+'|'+action+'|'+nameFirst+'|'+nameLast+'|'+phone1+'|'+phone2+'|';
		    phpString += email+'|'+officeNo+'|'+uPosition+'|'+uPublic;

		// Close form window
		contactsSupportObj.closeContactForm();
		
		x_saveContact(phpString,contactsViewObj.returnGetContactsForProgram);	 
	}
}

var contactsSupportObj = {
	openContactForm : function() {
		// Turn off add button
		$('buttonNew').style.display = 'none';				
		// Display add form
		new Effect.SlideDown('formNewContact', {direction: 'top', duration: .3});		
	},
	closeContactForm : function() {
		this.clearContactForm();
		
		// Rollup add form
		new Effect.SlideUp('formNewContact', {direction: 'top', duration: .3});
		
		// Reset hidden fields
		$('formAction').value = 'add';
		$('uID').value = '0';
		
		// Turn on add button
		$('buttonNew').style.display = '';	
	},
	clearContactForm : function() {
		$('uID').value        = '0';
		$('formAction').value = 'add';
		$('uNameFirst').value = '';
		$('uNameLast').value  = '';
		$('uPhone1').value    = '';
		$('uPhone2').value    = '';
		$('uEmail').value     = '';
		$('uOfficeNo').value  = '';
		$('uPosition').options.selectedIndex = 0;
		$('uPublic').checked  = false;
	},
	closeProgramForm : function(pID) {
		new Effect.SlideUp('programForm'+pID, {direction: 'top', duration: .3});		
		$('programInfo'+pID).style.display = '';
	}
}
